package com.wyn.common.controller;


/*控制层类的基类*/

import com.auth0.jwt.exceptions.JWTVerificationException;
import com.wyn.common.exception.ControllerException;
import com.wyn.common.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class BaseController {

    /*操作成功的状态码*/
    public static final int OK = 200;
    /*操作成功的信息*/
    public static final String OKMsg = "操作成功";
    /*操作失败的信息*/
    public static final String NOMsg = "操作失败";


    @ExceptionHandler(value = {ControllerException.class, JWTVerificationException.class})//用于统一处理抛出的异常
    @ResponseBody
    public R<Void> handleException(Throwable e) {
        R<Void> r = new R<>();
        if (e instanceof ControllerException) {
            r.setCode(4000);
            r.setMessage("数据异常");
        }
        return r;
    }
}
